#include "IFUException.h"
#include "IFUConf.h"

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

IFUConf::IFUConf(const string &filename) {
  this->filename = filename;
  read();
}

IFUConf::~IFUConf() {
}

void IFUConf::setNMaskHor(int nHor) {
  nMaskHor = nHor;
}

void IFUConf::setNMaskVer(int nVer) {
  nMaskVer = nVer;
}

void IFUConf::setMaskBasename(const string &basename) {
  maskBasename = basename;
}

void IFUConf::setMaskExt(const string &ext) {
  maskExt = ext;
}

void IFUConf::setColToAvg(int colAvg) {
  colToAvg = colAvg;
}

void IFUConf::setColStep(int step) {
  colStep = step;
}

void IFUConf::setNAgSim(int n) {
  nAgSim = n;
}

void IFUConf::setNGSim(int n) {
  nGSim = n;
}

void IFUConf::setAvgSigma(int avg) {
  avgSigma = avg;
}

void IFUConf::setPlot(bool b) {
  plot = b;
}

int IFUConf::getNMaskHor() {
  return nMaskHor;
}

int IFUConf::getNMaskVer() {
  return nMaskVer;
}

const string &IFUConf::getMaskBasename() {
  return maskBasename;
}

const string &IFUConf::getMaskExt() {
  return maskExt;
}

const string &IFUConf::getFilename() {
  return filename;
}

int IFUConf::getColToAvg() {
  return colToAvg;
}

int IFUConf::getColStep() {
  return colStep;
}

int IFUConf::getNAgSim() {
  return nAgSim;
}

int IFUConf::getNGSim() {
  return nGSim;
}

float IFUConf::getAvgSigma() {
  return avgSigma;
}

bool IFUConf::getPlot() {
  return plot;
}

void IFUConf::read() {

  ifstream infile;
  infile.open(filename.c_str());

  if (!infile.is_open())
    throw IFUException("Error openning conf: " + filename, "IFUConf");

  infile >> nMaskHor;      // number of mask steps in horizontal direction
  infile >> nMaskVer;      // number of mask steps in vertical direction
  infile >> maskBasename; // base name for mask image names
  infile >> maskExt;       // extension for mask image names
  infile >> colToAvg;   // number of columns to average when cutting the cols
  infile >> colStep ;     // number of columns to step through as we run fits

  infile.close();
 
}

void IFUConf::dump() {
  cout << nMaskHor << endl;
  cout << nMaskVer << endl;
  cout << maskBasename << endl;
  cout << maskExt << endl;
  cout << colToAvg << endl;
  cout << colStep << endl;
}
